import axios from '@/utils/http';
import base from './base';

export default {
  // 群组成员列表
  index(params) {
    return axios.get(
      `${base.sq}/groups/${params.groupId}/users`,
      {
        params: {
          nickname: params.searchName,
          page: params.page,
        },
      },
    );
  },
  // 群组成员列表（有活跃度）
  index2(params) {
    return axios.get(
      `${base.sq}/groups/${params.groupId}/users`,
      {
        params: {
          start_at: params.start_at,
          end_at: params.end_at,
          page: params.page,
        },
      },
    );
  },
  // 成员活跃
  memberActivities(params) {
    return axios.get(
      `${base.sq}/groups/${params.groupId}/user_collections`,
      {
        params: {
          user_id: params.userId,
          start_at: params.start_at,
          end_at: params.end_at,
        },
      },
    );
  },
  // 成员近期活动
  records(params) {
    return axios.get(
      `${base.sq}/groups/${params.groupId}/records`,
      {
        params: {
          user_id: params.memberId,
          type: params.type,
          start_at: params.start_at,
          end_at: params.end_at,
          page: params.page,
        },
      },
    );
  },
  // 移除群成员
  delete(params) {
    return axios.post(
      `${base.sq}/groups/${params.groupId}/remove_users`,
      {
        user_id: params.memberId,
      },
    );
  },
  // 修改成员权限
  setLevel(params) {
    return axios.post(
      `${base.sq}/groups/${params.groupId}/set_users`,
      {
        user_id: params.memberId,
        role: params.level,
      },
    );
  },
  // 获取群员活跃信息CSV
  getCSV(params) {
    return axios.post(
      `${base.sq}/groups/${params.groupId}/export_csv`,
      {
        start_at: params.start_at,
        end_at: params.end_at,
        product_id: params.spaceId,
      },
    );
  },
};
